package com.thd.springboottest.security.securitycustom;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * com.thd.springboottest.security.securitycustom.TokenToken
 *
 * @author: wanglei62
 * @DATE: 2022/6/23 11:15
 **/
public class JwtToken extends AbstractAuthenticationToken {
    // 认证信息,用于存储能识别用户的内容 例如：用户名/手机/邮箱
    private Object principal;
    // token字符串
    private String credentials;



    public JwtToken(Object principal, String credentials){
        super((Collection)null);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(true);
    }

    public JwtToken(Object principal, String credentials, Collection<? extends GrantedAuthority> authorities){
        super(authorities);
        this.principal = principal;
        this.credentials = credentials;
        this.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return this.credentials;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
